<template>
    <h1>登录页面</h1>
    <table class="table" border="1">
        <tbody>
            <tr>
                <td>管理员名称</td>
                <td>
                    <input type="text" v-model="Info.mname"/>
                </td>
            </tr>
            <tr>
                <td>密码</td>
                <td>
                    <input type="password" v-model="Info.pwd"/>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center;">
                    <input type="button" value="登录" @click="Login"/>
                </td>
            </tr>
        </tbody>
    </table>
</template>

<script setup lang="ts">
import { ref } from "vue";
import axios from "axios";
import { useRouter } from "vue-router";

const Info=ref({
    mid:0,
    mname:"",
    pwd:"",
})

const router=useRouter();
const Login=()=>{
    axios.get("https://localhost:7199/api/BingRoom/Login",{
        params:{
            mname:Info.value.mname,
            pwd:Info.value.pwd
        }
    })
    .then(res=>{
        if(res.data==-2){
            alert("管理员不存在");
        }
        else if(res.data==-1){
            alert("密码错误！")
        }
        else{
            alert("登录成功")
            router.push("/AddBingRoom")
        }
    })
    .catch(error=>{
        console.log(error);
    })
}
</script>